From f99e0aba70efad0deb907d8e27f09fc9f527c8a4 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Fri, 17 Feb 2023 17:07:50 +0700
Subject: Refactor

---
 src/pages/shop/product/[slug].jsx | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 src/pages/shop/product/[slug].jsx

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
new file mode 100644
index 00000000..84a3c7d4
--- /dev/null
+++ b/src/pages/shop/product/[slug].jsx
@@ -0,0 +1,29 @@
+import Seo from "@/core/components/Seo"
+import BasicLayout from "@/core/components/layouts/BasicLayout"
+import { getIdFromSlug } from "@/core/utils/slug"
+import productApi from "@/lib/product/api/productApi"
+import Product from "@/lib/product/components/Product"
+
+export async function getServerSideProps(context) {
+  const { slug } = context.query
+  let product = await productApi({ id: getIdFromSlug(slug) })
+  if (product?.length == 1) {
+    product = product[0]
+    product.description = product.description.replaceAll('<p>', '||p||')
+    product.description = product.description.replaceAll('</p>', '||/p||')
+    product.description = product.description.replace(/(<([^>]+)>)/gi, ' ')
+    product.description = product.description.replaceAll('||p||', '<p>')
+    product.description = product.description.replaceAll('||/p||', '</p>')
+    product.description = product.description.trim()
+  }
+  return { props: { product } }
+}
+
+export default function ProductDetail({ product }) {
+  return (
+    <BasicLayout>
+      <Seo title={product?.name} />
+      <Product product={product} />
+    </BasicLayout>
+  )
+}
\ No newline at end of file
-- 
cgit v1.2.3


From 69f55de26319e570ce0a8c4dbe8a29cb0d0b51c5 Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Sat, 18 Feb 2023 22:03:55 +0700
Subject: optimization

---
 src/pages/shop/product/[slug].jsx | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
index 84a3c7d4..2f610afb 100644
--- a/src/pages/shop/product/[slug].jsx
+++ b/src/pages/shop/product/[slug].jsx
@@ -1,8 +1,10 @@
 import Seo from "@/core/components/Seo"
-import BasicLayout from "@/core/components/layouts/BasicLayout"
 import { getIdFromSlug } from "@/core/utils/slug"
 import productApi from "@/lib/product/api/productApi"
-import Product from "@/lib/product/components/Product"
+import dynamic from "next/dynamic"
+
+const BasicLayout = dynamic(() => import("@/core/components/layouts/BasicLayout"))
+const Product = dynamic(() => import("@/lib/product/components/Product"))
 
 export async function getServerSideProps(context) {
   const { slug } = context.query
-- 
cgit v1.2.3


From f66b12fd1d0b83af0d7230d7b1565fbe00afbe3c Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Wed, 22 Feb 2023 11:03:34 +0700
Subject: prettier

---
 src/pages/shop/product/[slug].jsx | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

(limited to 'src/pages/shop/product/[slug].jsx')

diff --git a/src/pages/shop/product/[slug].jsx b/src/pages/shop/product/[slug].jsx
index 2f610afb..cc6924a3 100644
--- a/src/pages/shop/product/[slug].jsx
+++ b/src/pages/shop/product/[slug].jsx
@@ -1,10 +1,10 @@
-import Seo from "@/core/components/Seo"
-import { getIdFromSlug } from "@/core/utils/slug"
-import productApi from "@/lib/product/api/productApi"
-import dynamic from "next/dynamic"
+import Seo from '@/core/components/Seo'
+import { getIdFromSlug } from '@/core/utils/slug'
+import productApi from '@/lib/product/api/productApi'
+import dynamic from 'next/dynamic'
 
-const BasicLayout = dynamic(() => import("@/core/components/layouts/BasicLayout"))
-const Product = dynamic(() => import("@/lib/product/components/Product"))
+const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout'))
+const Product = dynamic(() => import('@/lib/product/components/Product'))
 
 export async function getServerSideProps(context) {
   const { slug } = context.query
@@ -28,4 +28,4 @@ export default function ProductDetail({ product }) {
       <Product product={product} />
     </BasicLayout>
   )
-}
\ No newline at end of file
+}
-- 
cgit v1.2.3

